[#import "/framework/JGP.htm"  as JGP]
<!--
项目   parent
作者   LOUFEI [Gavin]
时间   2018/4/13
-->
[@JGP.head "Title"/]
[@JGP.body]
    <jgp-div _row="['40','*']" _runit="px">
        <jgp-tools slot="1-1">
            <jgp-btn _fn="save">保存</jgp-btn>
        </jgp-tools>
        <jgp-panel slot="2-1" _padding="10px" _border="right">
            <jgp-tree _id="menuTree" _root="菜单树" _check="true" _single="false" _icon="false"
                      _onload="initTree"
                      _url="/security/admin/adminApiController/queryMenusTree"></jgp-tree>
        </jgp-panel>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        var selected;
        function initTree(){
            if(!selected){
                JGP.$get('/security/admin/adminApiController/queryRoleMenus/${roleId!''}', {},
                        function (result) {
                    console.log(result);
                            selected = result.data.menuIds;
                            JGP.tree('menuTree').setSelected(selected);
                        })
            }
        }
        function save() {
            var selected = JGP.tree('menuTree').getSelected();
            if (selected === -1) {
                JGP.$warn('没有选择角色');
                return;
            }
            var roleId = '${roleId!''}';
            var menuIds = [];
            for (var i = 0; i < selected.length; i++) {
                menuIds.push(selected[i].id);
            }
            JGP.$get('/security/admin/adminApiController/saveRoleMenus', {
                        menuIds: menuIds + '',
                        roleId: roleId
                    },
                    function (result) {
                        JGP.$alert('角色修改成功');
                    }, function () {
                        JGP.$error('错误');
                    })

        }
    </script>

[/@JGP.foot]